/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package visual;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.grapher.GrapherModule;
import com.google.inject.grapher.InjectorGrapher;
import com.google.inject.grapher.graphviz.GraphvizModule;
import com.google.inject.grapher.graphviz.GraphvizRenderer;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import module.MyModule;

public class Grapher {

    private void graph(String filename, Injector demoInjector) throws IOException {
        PrintWriter out = new PrintWriter(new File(filename), "UTF-8");

        Injector injector = Guice.createInjector(new GrapherModule(), new GraphvizModule());
        GraphvizRenderer renderer = injector.getInstance(GraphvizRenderer.class);
        renderer.setOut(out).setRankdir("TB");

        injector.getInstance(InjectorGrapher.class).of(demoInjector).graph();
    }

    public static void main(String[] args){
        try {
            Injector injector = Guice.createInjector(new MyModule());
            new Grapher().graph("myGraph.dot", injector);
        } catch (IOException ex) {
            Logger.getLogger(Grapher.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
